package com.ahms.web.controller.system;


import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ahms.common.annotation.Log;
import com.ahms.common.core.controller.BaseController;
import com.ahms.common.core.domain.AjaxResult;
import com.ahms.common.enums.BusinessType;
import com.ahms.common.utils.poi.ExcelUtil;
import com.ahms.common.core.page.TableDataInfo;
import com.ahms.customer.service.INewsImageService;
import com.ahms.customer.domain.NewsImage;
/**
 * 新闻图片Controller
 *
 * @author ruoyi
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/system/image")
public class SysNewsImageController extends BaseController
{
    @Autowired
    private INewsImageService newsImageService;

    /**
     * 查询新闻图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewsImage newsImage)
    {
        startPage();
        List<NewsImage> list = newsImageService.selectNewsImageList(newsImage);
        return getDataTable(list);
    }

    /**
     * 导出新闻图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:export')")
    @Log(title = "新闻图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewsImage newsImage)
    {
        List<NewsImage> list = newsImageService.selectNewsImageList(newsImage);
        ExcelUtil<NewsImage> util = new ExcelUtil<NewsImage>(NewsImage.class);
        util.exportExcel(response, list, "新闻图片数据");
    }

    /**
     * 获取新闻图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(newsImageService.selectNewsImageByImageId(imageId));
    }

    /**
     * 新增新闻图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:add')")
    @Log(title = "新闻图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsImage newsImage)
    {
        return toAjax(newsImageService.insertNewsImage(newsImage));
    }

    /**
     * 修改新闻图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:edit')")
    @Log(title = "新闻图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsImage newsImage)
    {
        return toAjax(newsImageService.updateNewsImage(newsImage));
    }

    /**
     * 删除新闻图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:remove')")
    @Log(title = "新闻图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(newsImageService.deleteNewsImageByImageIds(imageIds));
    }
}

